package com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler;

import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalKeyConsts;
import com.iwhalecloud.bss.kite.cucc.common.constant.LocalServiceOfferConsts;
import com.iwhalecloud.bss.kite.cucc.service.attr.LocalAttrHelper;
import com.iwhalecloud.bss.kite.cucc.service.attr.handler.LocalOpenPortAttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.annotation.AttrHandler;
import com.iwhalecloud.bss.kite.listener.handler.attr.impl.AbstractAttrLinkageHandler;
import com.iwhalecloud.bss.kite.manager.api.IQuerySceneInstService;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.manager.inst.KiteSceneInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.ztesoft.bss.common.util.SpringUtil;
import org.springframework.stereotype.Service;

import java.util.Objects;

/**
 * <Description> <br>
 *
 * @author cheng.leizhen01<br>
 * @version 1.0<br>
 * @taskId <br>
 * @CreateDate 2021年3月16日 <br>
 * @since R9.0<br>
 * @see com.iwhalecloud.bss.kite.cucc.service.attr.linkhandler <br>
 */
@Service
@AttrHandler(LocalOpenPortAttrHandler.class)
public class LocalOpenPortAttrLinkHandler extends AbstractAttrLinkageHandler<AttrData> {
    /**
     *域名  当是否域名解析为‘是’时，显示且必填
     * 掩码  当是否域名解析为‘是’时，显示且必填
     * AS NUMBER  当是否域名解析为‘是’时，显示且必填
     */

    @Override
    public void handle(KiteAttr attr, KiteInst inst, AttrData data) {
        if (Objects.isNull(attr)) {
            return;
        }
        IQuerySceneInstService querySceneInstService = SpringUtil.getBean(IQuerySceneInstService.class);
        KiteSceneInst sceneInst = querySceneInstService.getSceneInst(data.getSceneInstId());
        String nodeCode = querySceneInstService.getExtParameterValue(data.getSceneInstId(), "nodeCode");
        String provinceCode = sceneInst.getProvinceNbr();
        String serviceOfferId = data.getServiceOfferId();
        boolean flag = false, isGuangdong = false;
        if (LocalKeyConsts.PROVINCE_GUANGDONG.equals(provinceCode)) {
            isGuangdong = true;
            if (KiteStringUtils.equalsAny(nodeCode,"OrderSigned","OrderResubmit","OrderAudit","OrderInput")||
                KiteStringUtils.equalsAny(serviceOfferId,"1","2826", LocalServiceOfferConsts.SERVICE_OFFER_RESOURCE_CHECK)) {
                flag = true;
            }
        }
        KiteAttr kiteAttr = inst.getAttr("210004029");
        KiteAttr wzbahkiteAttr = inst.getAttr("2_0000204");
        if (isGuangdong) {
            kiteAttr.setCname("备案IP");
            kiteAttr.setProductAttrDesc("xx;xx");
            wzbahkiteAttr.setProductAttrDesc("xx;xx");
            if (KiteStringUtils.equals("200001833",attr.getFieldName())) {
                attr.setCol1("80/8080/443反向访问端口");
            }
        }
        //IP备案字段  210004029
        //网站备案号  2_0000204
        //开设网站域名  2_0000196
        if(KiteStringUtils.equalsAny(attr.getValue(),"1_0000106" )){
            LocalAttrHelper.showAndNotNull(inst, "210004029");
            if (flag) {
                LocalAttrHelper.showAndNull(inst, "2_0000204");
                LocalAttrHelper.showAndNull(inst, "2_0000196");
            }
        } else {
            LocalAttrHelper.hideAndNullable(inst, "210004029");
            if (flag) {
                LocalAttrHelper.hideAndNullable(inst, "2_0000204");
                LocalAttrHelper.hideAndNullable(inst, "2_0000196");
            }
        }
    }

    @Override
    public void handleStyle(KiteAttr attr, KiteInst inst, AttrData data) {

    }

}
